/***************************************************************************
 *   KShootout - online shootout card game.                                *
 *   Copyright (C) 2008, 2009  MacJariel                                   *
 *                                                                         *
 *   KShootout is free software: you can redistribute it and/or modify     *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   KShootout is distributed in the hope that it will be useful,          *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with KShootout.  If not, see <http://www.gnu.org/licenses/>.    *
 ***************************************************************************/
#ifndef __CHARACTERWIDGET_H__
#define __CHARACTERWIDGET_H__

#include "gametypes.h"
#include <QWidget>
#include <QTime>

namespace client
{
    class GameActionMgr;
    class CardWidget;

    /**
     * The CharacterWidget class provides a widget to show player's character
     * card and to show his lifepoints.
     * @author MacJariel
     */
    class CharacterWidget: public QWidget
    {
        Q_OBJECT;
    public:
        /// Constructs a clean CharacterWidget instance.
        CharacterWidget(QWidget* parent = 0);

        /// Destroys the instance.
        virtual ~CharacterWidget();

        /// Returns the character of this character widget.
        QString character() const;

        /// Returns the life points of this character widget.
        int lifePoints() const;

        /// Returns recommended size for the widget.
        virtual QSize sizeHint() const;

        /// Character widgets need to generate game events. Pointer to the
        /// game-action manager should be provided as soon as possible.
        void setGameActionMgr(GameActionMgr* gameActionMgr);

        /// Sets the id of the player, that owns this character widget.
        void setPlayerId(PlayerId playerId);

        /// Sets the character of this CharacterWidget.
        void setCharacter(const QString& character);

        /**
         * Sets the life points of this CharacterWidget. If life points
         * changes, an animation is started and animationFinished() signal
         * is emitted when the animation finishes.
         */
        void setLifePoints(int lifePoints);

    protected:
        virtual void timerEvent(QTimerEvent* event);

    private:
        void startAnimation();

    public slots:
        void updateWidgetSize();

    signals:
        void animationFinished();

    private:
        QString     m_character;
        int         m_lifePoints;
        int         m_sourceY;
        int         m_targetY;
        CardWidget* mp_backCard;
        CardWidget* mp_characterCard;
        int         m_animationTimer;
        QTime       m_time;
    };

    inline int CharacterWidget::lifePoints() const
    {
        return m_lifePoints;
    }
}
#endif // __CHARACTERWIDGET_H__
